/**
 * 
 */
package com.wolfpire.proms.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.wolfpire.proms.dao.ProjectIndexDao;
import com.wolfpire.proms.dao.TaskDao;
import com.wolfpire.proms.dao.TaskPlanDao;
import com.wolfpire.proms.model.ProjectIndex;
import com.wolfpire.proms.model.Task;
import com.wolfpire.proms.model.TaskPlan;
import com.wolfpire.proms.service.TaskPlanService;
import com.wolfpire.system.common.Constants;
import com.wolfpire.system.common.EasyuiPage;
import com.wolfpire.system.common.Page;
import com.wolfpire.system.common.base.dao.IBaseHibernateDao;
import com.wolfpire.system.common.base.service.impl.BaseHibernateService;
import com.wolfpire.system.model.User;
import com.wolfpire.system.service.AttachmentService;
import com.wolfpire.workflow.em.OperateType;
import com.wolfpire.workflow.om.ProInstance;
import com.wolfpire.workflow.spring.WorkflowService;
import com.wolfpire.workflow.spring.impl.JbpmTaskService;

/**
 * @author hj
 *
 */

@Service("taskPlanService")
public class TaskPlanServiceImpl extends BaseHibernateService<TaskPlan, Long> implements
		TaskPlanService {
	
	@Resource private TaskPlanDao taskPlanDao;
	
	@Resource private ProjectIndexDao projectIndexDao;
	
	@Resource private AttachmentService attachmentService;
	
	@Resource private WorkflowService workflowService;
	
	@Resource private JbpmTaskService jbpmTaskService;

	@Override
	protected IBaseHibernateDao<TaskPlan, Long> getEntityDao() {
		return this.taskPlanDao;
	}
	
	@Override
	public Page<TaskPlan> setPageDataTaskPlanList(Page<TaskPlan> page,
			TaskPlan filterTaskPlan) {
		return this.taskPlanDao.findTasks(page, filterTaskPlan);
	}

	@Override
	public void saveOrUpdateTaskPlan(TaskPlan taskPlan, User user) {
		if (null == taskPlan.getId()) {
			taskPlan.setCreateUserId(user.getId());
			taskPlan.setCreateUserName(user.getNickName());
			taskPlan.setStatus(0);
		} else {
			taskPlan.setUpdateTime(new Date());
			taskPlan.setUpdateUserId(user.getId());
			taskPlan.setUpdateUserName(user.getNickName());
		}
		this.taskPlanDao.saveOrUpdate(taskPlan);
	}

	@Override
	public TaskPlan getTaskPlan(Long id) {
		return this.taskPlanDao.get(id);
	}

	@Override
	public void delTaskPlan(Long id) {
		TaskPlan taskPlan = this.taskPlanDao.get(id);
		if (null != taskPlan.getTaskId()) {
			this.taskPlanDao.delete(id);
		} else {
			if (null != taskPlan) {
				taskPlan.setDelFlag(Constants.DELETE_FLAG);
				this.taskPlanDao.saveOrUpdate(taskPlan);
			}
		}
	}

	@Override
	public List<TaskPlan> list(TaskPlan entity) {
		return null;
	}
}
